﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Weazel.Willows.PreliminaryModel
{
	public class WaitTransition
		: Weazel.Willows.Model.WaitTransition
	{
		public WaitTransition(XmlElement xmlElement)
		{
			read(xmlElement);
		}

		private WaitTransition()
		{
		}

		public WaitTransition Clone()
		{
			WaitTransition clone = new WaitTransition();

			clone.targetStateName = this.targetStateName;
			foreach (string waitElement in WaitList)
				clone.WaitList.Add(waitElement);

			return clone;
		}

		private void read(XmlElement description)
		{
			System.Diagnostics.Trace.Assert(description.Name == "Wait");
			
			this.targetStateName = description.Attributes["target"].Value;
			
			foreach (XmlElement element in description.GetElementsByTagName("QueueReadyEvent"))
			{
				System.Diagnostics.Trace.Assert(element.HasAttribute("name"));

				// add queue name to wait list
				this.waitList.Add(element.Attributes["name"].Value);
			}
		}
	}
}
